﻿@using PagedList.Mvc;
@model BBICMS.Model.ViewModel.Back.PostListVM

@{
    var modelName = "文章";
    ViewBag.PageTitle = modelName;
    ViewBag.Title = ViewBag.PageTitle + "_内容";
   
}



    <div class="panel panel-default">
        <header class="panel-heading">
            <div class="pull-right">
                <a class="btn btn-primary" href="@Url.Action("AddPost")"><i class="glyphicon glyphicon-plus"></i> 添加新闻</a>
                <a class="btn btn-default" href="@Url.Action("AddBlog")"><i class="glyphicon glyphicon-plus"></i> 添加分类</a>
            </div>
            <form class="form-inline">
                <div class="form-group">
                    <label for="BlogId">分类</label>
                    @Html.DropDownListFor(model => model.BlogId, Model.Blogs, new { @class = "form-control" })
                </div>
                <div class="form-group">
                    <label for="BlogId">关键字</label>
                    @Html.TextBoxFor(model => model.Keyword, new { @class = "form-control" })
                </div>
                <button type="submit" class="btn btn-primary"><i class="fa fa-search fa-fw"></i>查找</button>
            </form>           
        </header>
             

            <table class="table table-hover table-striped table-vmiddle">
                <thead>
                    <tr>
                        <th></th>
                        <th>
                            主题
                        </th>
                        <th>
                            分类
                        </th>
                        <th>
                            查看
                        </th>
                        <th>
                            语言
                        </th>
                        @*<th>
                            <span class="glyphicon glyphicon-user"></span> 发布者
                        </th>*@
                        <th>
                            <span class="glyphicon glyphicon-time"></span> 发布日期
                        </th>
                        <th>
                            推荐？
                        </th>
                        <th>
                            显示？
                        </th>
                      
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.PostList)
                    {
                        <tr class="item-container">
                            <td>
                                @if (!string.IsNullOrEmpty(item.Thumbnail))
                                {
                                    <img src="@string.Format("{0}?width=80&mode=width", item.Thumbnail)" class="img-thumbnail" />
                                }
                            </td>

                            <td>
                                @item.Title
                            </td>

                            <td>
                                @item.Blog.Title
                            </td>
                            <td>
                                @item.ViewCount
                            </td>
                            <td>
                              <img src="@BBICMS.Repository.LanguageHelper.GetCultureIcon(item.Lang)" alt="@item.Lang" />
                            </td>
                            @*<td>
                                @item.AddedBy
                            </td>*@

                            <td>@string.Format("{0:d}", item.Pubdate)</td>
                            <td>
                                @if (item.Recommend)
                                {
                                    <a href="#" data-url="@Url.Action("IsRecommend", new {id = item.Id})" class="recommend-item" title="推荐" data-action="撤消推荐">
                                        <i class="fa fa-check text-success"></i>
                                    </a>

                                }
                                else
                                {
                                    <a href="#" data-url="@Url.Action("IsRecommend", new {id = item.Id})" class="recommend-item" title="不推荐" data-action="推荐">
                                        <i class="fa fa-remove text-danger"></i>
                                    </a>
                                }
                            </td>

                            <td>
                                @if (item.Active)
                                {
                                    <a href="#" data-url="@Url.Action("IsActive", new {id = item.Id})" class="active-item" title="激活" data-action="锁定">
                                        <i class="fa fa-check text-success"></i>
                                    </a>

                                }
                                else
                                {
                                    <a href="#" data-url="@Url.Action("IsActive", new {id = item.Id})" class="active-item" title="锁定" data-action="激活">
                                        <i class="fa fa-remove text-danger"></i>
                                    </a>
                                }
                            </td>

                            <td>
                                <a href="@Url.Action("EditPost", new { Id = item.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                                <a href="@Url.Action("DeletePost", new { Id = item.Id })" class="btn btn-xs btn-danger delete-item"><i class="glyphicon glyphicon-trash"></i></a>
                            </td>
                        </tr>
                    }

                </tbody>

            </table>




        <footer class="panel-footer">
            <div class="row">
                <div class="col-sm-7">
                    @Html.PagedListPager((IPagedList)Model.PostList, page => Url.Action("Index", new { page, blogId = Model.BlogId }))
                </div>
                <div class="col-sm-5">
                    <div class="text-right form-inline">
                        总计 @Model.TotalCount 条，
                        分页：                  
                        @Html.DropDownListFor(model => model.PageSize, (SelectList)ViewBag.PageSizes, new { @class = "form-control" })                        
                      
                    </div>
                </div>
            </div>
        </footer>
    </div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

<!-- end main container -->
@section footer {
<script src="~/Content/bootstrap/plugins/bootbox/bootbox.min.js"></script>
    <script>


        $(function () {
            //当前菜单;
            $('.mainmenu>li:nth-of-type(1)').addClass('nav-open').find('.submenu li:nth-of-type(1) a').addClass('active');

            var modelName = "@modelName";

            //分类过滤文章
            $("#PageSize").change(function () {
                var pagesize = $(this).val();
                var url = "@Url.Action("UpdatePagesize")";
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "POST",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({ pagesize: pagesize }),               
                    success: function (data) {
                        if (data.Status === 1) {
                            location.reload();
                        }
                    }
                });
            });


            $('.recommend-item,.active-item').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('data-url'), title = $(this).attr('data-action'), that = $(this);

                Common.SingleAction(url, title, that);

            });

            //删除数据
            $('.delete-item').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href'), that = $(this), title = '@string.Format("删除{0}", EntityNames.Article)';

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        Common.DeleteItem(url, title, that);
                    }
                });
            });


            @*//删除数据
            $('.delete-post').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href');
                //      var confireMes = $(this).attr('data-confirm');            
                var that = $(this);

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        $.post(url, $("#anti-form").serialize(), function (data) {

                            if (data.Status === 1) {
                                toastr.success("已成功删除此项", '@ViewBag.Title');

                                setTimeout(function () {
                                    location.reload();
                                }, 1000);
                                
                            } else {
                                toastr.error(data.Message, '@ViewBag.Title');
                            }

                        });
                    }
                });
            });*@


          

        });
    </script>

}